namespace RushMail.Requests;

public class TemplateCategory
{
    private readonly IRushMailClient _client;

    public TemplateCategory(IRushMailClient client)
    {
        _client = client;
    }

    /// <summary>
    /// 模板分类列表
    /// http://edmapi.rushmail.com/api.php?module=wc-template&action=category-list
    /// </summary>
    /// <returns></returns>
    public async Task<RushMailResponse<CategoryListResponse>> List() =>
        (await _client.PostAsync(new RushMailRequest("wc-template", "category-list"))).ToGeneric<CategoryListResponse>();
    
    /// <summary>
    /// 模板分类新增
    /// http://edmapi.rushmail.com/api.php?module=wc-template&action=category-add
    /// </summary>
    /// <returns></returns>
    public async Task<RushMailResponse<int>> Add(string name) =>
        (await _client.PostAsync(new RushMailRequest("wc-template", "category-add")
        {
            Body = new Dictionary<string, string>() { {"name", name} }
        }))
        .ToGeneric<int>();
    
    /// <summary>
    /// 模板分类修改
    /// http://edmapi.rushmail.com/api.php?module=wc-template&action=category-edit
    /// </summary>
    /// <returns></returns>
    public Task<RushMailResponse> Edit(int categoryId, string name) =>
        _client.PostAsync(new RushMailRequest("wc-template", "category-edit")
        {
            Body = new Dictionary<string, string>() { {"category_id", categoryId.ToString()}, {"name", name} }
        });
    
    /// <summary>
    /// 模板分类删除
    /// http://edmapi.rushmail.com/api.php?module=wc-template&action=category-delete
    /// </summary>
    /// <returns></returns>
    public Task<RushMailResponse> Delete(int categoryId) =>
        _client.PostAsync(new RushMailRequest("wc-template", "category-delete")
        {
            Body = new Dictionary<string, string>() { {"category_id", categoryId.ToString()} }
        });
}

